package com.netty.service.impl;

import com.annotation.Cmd;
import com.annotation.Module;
import com.common.protobuf.Result;
import com.common.protobuf.UserModule;
import com.google.protobuf.InvalidProtocolBufferException;
import com.netty.service.UserService;
import org.springframework.stereotype.Service;

/**
 * @author 顾志杰
 * @date 2021/3/16-10:02
 */
@Service
@Module(module = "user")
public class UserServiceImpl implements UserService {

    @Override
    @Cmd(cmd = "save")
    public Result<?> save(byte[] data){
        UserModule.User user = null;
        try {
             user = UserModule.User.parseFrom(data);
            System.out.println("save ok,userId: " + user.getUserId() + ",userName" + user.getUserId());
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
            return Result.FAILURE();
        }
        return Result.SUCCESS(user);
    }

    @Override
    @Cmd(cmd = "update")
    public Result<?> update(byte[] data){
        UserModule.User user = null;
        try {
            user = UserModule.User.parseFrom(data);
            System.out.println("update ok,userId: " + user.getUserId() + ",userName" + user.getUserId());
        } catch (InvalidProtocolBufferException e) {
            e.printStackTrace();
            return Result.FAILURE();
        }
        return Result.SUCCESS(user);
    }
}
